component accessors="true" extends="controllerbase" {
	property sms;
	this.entityObj ="sms";
	//发送
	public void function getSendBoxList(rc){
		if(!structKeyExists(rc, "rows") || (!isNumeric(rc.rows) || rc.rows <= 0 || round(rc.rows) != rc.rows))
		{
			rc.rows = request.rows;
		}

		if(!structKeyExists(rc, "page") || (!isNumeric(rc.page) || rc.page <= 0 || round(rc.page) != rc.page))
		{
			rc.page = 1;
		}

		/*查询条件*/
		rc.sqlWhere = " 1 = 1 and fromUserId = #session.auth.userid# ";

		if( structKeyExists(rc, "subject") && len(trim(rc.subject)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and subject like '%" & subject & "%' " ;
		}

		if( structKeyExists(rc, "created_ge") && len(trim(rc.created_ge)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and created >= '" & rc.created_ge & "'" ;
		}

		if( structKeyExists(rc, "created_le") && len(trim(rc.created_le)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and created =< '" & rc.created_le & "'" ;
		}

		if( structKeyExists(arguments, "moduleSqlWhere") && len(trim(arguments.moduleSqlWhere))>0 ){
			rc.sqlWhere = rc.sqlWhere & moduleSqlWhere;
		}

		/*排序条件*/
		if( structKeyExists(rc, "sort")  && len(trim(rc.sort))>0 )
		{
			rc.sqlSort = " order by " & rc.sort & " ";
		}else{
			rc.sqlSort = "  order by id ";
		}

		if( structKeyExists(rc, "order")  && len(trim(rc.order))>0 )
		{
			rc.sqlSort = rc.sqlSort  &  rc.order;
		}else{
			rc.sqlSort = rc.sqlSort & " desc ";

		}

		rc.data = variables.sms.getSendBoxList(rc);
		variables.fw.renderData('json', rc.data);
	}

	public void function getInBoxList(rc){
		if(!structKeyExists(rc, "rows") || (!isNumeric(rc.rows) || rc.rows <= 0 || round(rc.rows) != rc.rows))
		{
			rc.rows = request.rows;
		}

		if(!structKeyExists(rc, "page") || (!isNumeric(rc.page) || rc.page <= 0 || round(rc.page) != rc.page))
		{
			rc.page = 1;
		}

		/*查询条件*/
		rc.sqlWhere = " 1 = 1 and l.touserid = #session.auth.userid# ";

		if( structKeyExists(rc, "subject") && len(trim(rc.subject)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and s.subject like '%" & subject & "%' " ;
		}

		if( structKeyExists(rc, "created_ge") && len(trim(rc.created_ge)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and s.created >= '" & rc.created_ge & "'" ;
		}

		if( structKeyExists(rc, "created_le") && len(trim(rc.created_le)) >0 ){
			rc.sqlWhere = rc.sqlWhere & " and s.created =< '" & rc.created_le & "'" ;
		}

		/*排序条件*/
		if( structKeyExists(rc, "sort")  && len(trim(rc.sort))>0 )
		{
			rc.sqlSort = " order by s." & rc.sort & " ";
		}else{
			rc.sqlSort = "  order by s.id ";
		}

		if( structKeyExists(rc, "order")  && len(trim(rc.order))>0 )
		{
			rc.sqlSort = rc.sqlSort  &  rc.order;
		}else{
			rc.sqlSort = rc.sqlSort & " desc ";

		}

		rc.data = variables.sms.getInBoxList(rc);
		variables.fw.renderData('json', rc.data);
	}


	public void function save(rc){
		if( structKeyExists(rc, "organizationids")  && listlen(rc.organizationids) > 0 ){
			rc.organizationids = rc.organizationids;
		}else{
			rc.organizationids = 0;
		}

		if( structKeyExists(rc, "roleids")  && listlen(rc.roleids) > 0 ){
			rc.roleids = rc.roleids;
		}else{
			rc.roleids = 0;
		}

		if( structKeyExists(rc, "userids")  && listlen(rc.userids) > 0 ){
			rc.userids = rc.userids;
		}else{
			rc.userids = 0;
		}

		if( structKeyExists(rc, "alluser")  && len(rc.alluser) > 0 ){
			rc.alluser = rc.alluser;
		}else{
			rc.alluser = 0;
		}

		rc.data = variables.sms.save(rc);
		variables.fw.renderData('json', rc.data);
	}

	public void function replysms(rc){
		rc.data = variables.sms.replysms(rc);
		variables.fw.renderData('json', rc.data);
	}

	public void function get(rc){
		if( structKeyExists(rc, "id") && len(trim(rc.id)) >0 ){
			rc.id = rc.id;
		}else{
			rc.id = 0;
		}

		rc.json = variables.sms.get(rc);
		variables.fw.renderData('json', rc.json);
	}

	public void function deletesendbox(rc){
		variables.sms.deletesendbox(rc.id);
		variables.fw.renderData('json', true);
	}

	public void function deleteinbox(rc){
		variables.sms.deleteinbox(rc.id);
		variables.fw.renderData('json', true);
	}

}